<template>
	<om-formsub-outer :index="index" :checkedit="checkedit" :deleteBtn="false">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId'])
		},
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData()
		},
		methods:{
			onSelectInterviewFlag(data){
				let _that = this
				_that.$refs.autoform.formdata.interviewFlagName = data.name
			},
			onSelectBusinessDirector(data){
				let _that = this
				_that.om.request('/tlApply/findBusinessDirectorInstList', {
					userId: data.userId
				}).then(res => {
					let arr = res;
					if(arr.length>0){
						_that.$refs.autoform.formdata.instId = arr[0].id
						_that.$refs.autoform.formdata.instName = arr[0].instName
						_that.$refs.autoform.changeEditor("businessDirectorInfo", "instId", "data", configSelectData(arr,"id","instName"))
						_that.$refs.autoform.initSelectIndex("businessDirectorInfo", "instId")
					}else{
						_that.om.toast(res.msg);
					}
				})
			}
		},
		onShow() {
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								_that.autoformdata[0].order = _that.order
								if(e.isCheck == "true"){
									changeEditor('businessDirectorInfo',"businessDirectorId","type","labelbox",_that.autoformdata)
									changeEditor('businessDirectorInfo',"instId","type","labelbox",_that.autoformdata)
								}
								_that.om.request('/tlApply/findBusinessDirectorData').then(res => {
									if(res.length>0){
										_that.$nextTick(function(){
											_that.$refs.autoform.changeEditor("businessDirectorInfo", "businessDirectorId", "data", configSelectData(res,"userId","userName"))
											_that.$refs.autoform.initSelectIndex("businessDirectorInfo", "businessDirectorId")
											if(_that.$refs.autoform.formdata.businessDirectorId){
												_that.om.request('/tlApply/findBusinessDirectorInstList', {
													userId: _that.$refs.autoform.formdata.businessDirectorId
												}).then(res => {
													let arr = res;
													if(arr.length>0){
														if(!_that.$refs.autoform.formdata.instId){
															_that.$refs.autoform.formdata.instId = arr[0].id
															_that.$refs.autoform.formdata.instName = arr[0].instName
														}
														_that.$refs.autoform.changeEditor("businessDirectorInfo", "instId", "data", configSelectData(arr,"id","instName"))
														_that.$refs.autoform.initSelectIndex("businessDirectorInfo", "instId")
													}else{
														_that.om.toast(res.msg);
													}
												})
											}
										})
									}else{
										_that.om.toast(res.msg);
									}
								})
								_that.om.request('/dictZero/findBooleanDtoList').then(res => {
									if(res.length>0){
										_that.$nextTick(function(){
											if(_that.userId == _that.formdata.businessDirectorId){
												_that.$refs.autoform.changeEditor("businessDirectorInfo", "interviewFlag", "data", configSelectData(res,"value","name"))
												_that.$refs.autoform.initSelectIndex("businessDirectorInfo", "interviewFlag")
											}else{
												_that.$refs.autoform.changeEditor("businessDirectorInfo","interviewFlag","type","labelbox")
												_that.$refs.autoform.changeEditor("businessDirectorInfo","opinion","type","labelbox")
											}	
										})		
									}else{
										_that.om.toast(res.msg);
									}
								})

							}
						}
					})
				}			
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
